package com.zxj.friend.manager;

import com.zxj.common.core.contains.CacheConstants;
import com.zxj.common.redis.service.RedisService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.stereotype.Component;

/**
 * 用户竞赛缓存管理器
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class UserExamCacheManager {
    private final RedisService redisService;

    /**
     * 添加用户竞赛缓存
     * @param userId 用户id
     * @param examId 竞赛id
     */
    public void addUserExamCache(Long userId, Long examId) {
        String userExamListKey = getUserExamListKey(userId);
        redisService.leftPushForList(userExamListKey, examId);
    }


    /**
     * 获取用户竞赛缓存key
     * @param userId 用户id
     * @return 缓存key = u:e:l:${userId}
     */
    private String getUserExamListKey(Long userId) {
        return CacheConstants.USER_EXAM_LIST + userId;
    }
}
